<?php
// parameters
$sQuery = (isset($_POST['query'])?$_POST['query']:'');
$iStart = (isset($_POST['start'])?$_POST['start']:0);
$iSize = (isset($_POST['size'])?$_POST['size']:20);
$sDataStore = $_GET['ds'];
if(!$sKeywords) {
    print $GLOBALS['_ObjectResponse']->getResponse(array());
    exit(0);
}


// get query object
$oQueryParser = new QueryParser();
$oQuery = $oQueryParser->query($sQuery);
unset($oQueryParser);


// query
$sDatabasePath = $GLOBALS['DataStores'][$sDataStore]['path'];
$oDatabase = new XapianDatabase($sDatabasePath);
$oEnquire = new XapianEnquire($oDatabase);

$oEnquire->set_query($oQuery);

$oMatches = $oEnquire->get_mset($iStart, $iSize);
$nTotal = $oMatches->get_matches_estimated();

$aResponseArray = array();
$i = $oMatches->begin();
while (!$i->equals($oMatches->end())) {
    $aResponseArray[] = array(
        "rank" => $i->get_rank(),
        "key" => $i->get_document()->get_value(0)
    );
    $i->next();
}


// response
print $GLOBALS['_ObjectResponse']->getResponse($aResponseArray);

?>